
const _interopRequireDefault = require('@babel/runtime/helpers/interopRequireDefault');

exports.__esModule = true;
exports.default = void 0;

const _extends2 = _interopRequireDefault(require('@babel/runtime/helpers/extends'));

const _babelHelperVueJsxMergeProps = _interopRequireDefault(require('@vue/babel-helper-vue-jsx-merge-props'));

const _utils = require('../utils');

const _functional = require('../utils/functional');

const _tag = _interopRequireDefault(require('../tag'));

const _icon = _interopRequireDefault(require('../icon'));

const _cell = _interopRequireDefault(require('../cell'));

const _radio = _interopRequireDefault(require('../radio'));

// Utils
// Components
const _createNamespace = (0, _utils.createNamespace)('address-item');
const createComponent = _createNamespace[0];
const bem = _createNamespace[1];

function AddressItem(h, props, slots, ctx) {
  const { disabled } = props;
  const { switchable } = props;

  function onClick() {
    if (switchable) {
      (0, _functional.emit)(ctx, 'select');
    }

    (0, _functional.emit)(ctx, 'click');
  }

  const genRightIcon = function genRightIcon() {
    return h(_icon.default, {
      attrs: {
        name: 'edit',
      },
      class: bem('edit'),
      on: {
        click: function click(event) {
          event.stopPropagation();
          (0, _functional.emit)(ctx, 'edit');
          (0, _functional.emit)(ctx, 'click');
        },
      },
    });
  };

  function genTag() {
    if (props.data.isDefault && props.defaultTagText) {
      return h(_tag.default, {
        attrs: {
          type: 'danger',
          round: true,
        },
        class: bem('tag'),
      }, [props.defaultTagText]);
    }
  }

  function genContent() {
    const { data } = props;
    const Info = [h('div', {
      class: bem('name'),
    }, [`${data.name} ${data.tel}`, genTag()]), h('div', {
      class: bem('address'),
    }, [data.address])];

    if (switchable && !disabled) {
      return h(_radio.default, {
        attrs: {
          name: data.id,
          iconSize: 18,
        },
      }, [Info]);
    }

    return Info;
  }

  return h('div', {
    class: bem({
      disabled,
    }),
    on: {
      click: onClick,
    },
  }, [h(_cell.default, (0, _babelHelperVueJsxMergeProps.default)([{
    attrs: {
      border: false,
      valueClass: bem('value'),
    },
    scopedSlots: {
      default: genContent,
      'right-icon': genRightIcon,
    },
  }, (0, _functional.inherit)(ctx)])), slots.bottom == null ? void 0 : slots.bottom((0, _extends2.default)({}, props.data, {
    disabled,
  }))]);
}

AddressItem.props = {
  data: Object,
  disabled: Boolean,
  switchable: Boolean,
  defaultTagText: String,
};

const _default = createComponent(AddressItem);

exports.default = _default;
